<?php
/**
 * Created by 张彪.
 * User: 小马出行
 * Date: 2018/5/22
 * Time: 13:14
 */
namespace app\admin\controller;
use think\Db;

class AppLog extends Base
{
    /**
     * APP操作日志
     * @param string
     * @param int
     * @return string 成功时返回
     */
    public function index(){
        $page = input('get.page');
        $limit = input('get.limit');
        $where = array();
        if ($page && $limit) {
            $start = strtotime(input('get.start'));
            $end = strtotime(input('get.end'));
            input('get.start')&&$where['time'] = array('egt',$start);
            input('get.end')&&$where['time'] = array('elt',$end);
            input('get.start')&&input('get.end')&&$where['time'] = array('between',array($start,$end));
            $count = Db::table('api_log')->field('id,param,time,url')->where($where)->count();
            $res = Db::table('api_log')->where($where)->page($page, $limit)->order('time desc')->select();
            foreach ($res as $key => $value) {
                $res[$key]['url'] = json_decode($value['url']);
                $res[$key]['time'] = date('Y-m-d H:i:s');
            }
            return json(array(
                'code' => 0,
                'msg' => '',
                'count' => $count,
                'data' => $res

            ));
        }
        $this->assign('url',url('index'));
        return $this->fetch();
    }

    /**
     * APP操作日志详情
     * @param string
     * @param int
     * @return string 成功时返回
     */
    public function detail(){
        $id = input('get.id');
        $content = Db::table('api_log')->where('id',$id)->value('content');
        $content = json_decode($content);
        $this->assign('content',$content);
        return $this->fetch();

    }
}